package com.CoreryBlack.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
//@Aspect
public class MyAspect1 {

    @Pointcut("execution(* com.CoreryBlack.service.Impl.DeptServiceImpl.*(..))")
    public void pt(){}

    //原始方法运行前
    @Before("pt()")
    public void before(){
        log.info("MyAspect1 ... before ...");
    }

    //原始方法运行前 - 原始方法 - 后
    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("MyAspect1 ... around before ...");

        Object result = pjp.proceed();

        log.info("MyAspect1 ... around before ...");
        return result;
    }

    //原始方法运行后
    @After("pt()")
    public void after(){
        log.info("MyAspect1 ... after ...");
    }

    //原始方法运行后 - 方法正常执行返回
    @AfterReturning("pt()")
    public void afterReturning(){
        log.info("MyAspect1 ... afterReturning ...");
    }

    //原始方法运行后 - 方法执行出现异常
    @AfterThrowing("pt()")
    public void afterThrowing(){
        log.info("MyAspect1 ... afterThrowing ...");
    }

}
